const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        key: '',
        order_id: '',
        order_info: {},
        deliver_info: {}
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var self = this;
        self.setData({
            order_id: options.order_id
        })
        wx.getStorage({
            key: 'key',
            success: res => {
                self.setData({
                    key: res.data
                })
                self.getOderInfo(res.data, options.order_id);
            }
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    getOderInfo: function (key, order_id) {
        var self = this;
        wx.request({
            url: app.globalData.ApiUrl + '/index.php?act=member_order&op=order_info',
            data: {
                key: key,
                order_id: order_id
            },
            method: 'GET',
            dataType: 'json',
            success: res => {
                if (res.data.code == 200) {
                    self.setData({
                        order_info: res.data.datas.order_info,
                    })
                } else {
                    wx.showToast({
                        title: res.data.datas.error,
                        icon: 'none'
                    })
                }
            }
        })
        wx.request({
            url: app.globalData.ApiUrl + '/index.php?act=member_order&op=get_current_deliver',
            data: {
                key: key,
                order_id: order_id
            },
            method: 'POST',
            header: {
                'content-type': 'application/x-www-form-urlencoded'
            },
            dataType: 'json',
            success: res => {
                var data = res && res.data.datas;
                if (data.deliver_info) {
                    self.setData({
                        deliver_info: data.deliver_info
                    })
                }
            }
        })
    },
    makePhoneCall: function (e) {
        let store_phone = e.currentTarget.dataset['store_phone'];
        wx.makePhoneCall({
            phoneNumber: store_phone,
        })
    },
    goodsDetail: function (e) {
        let goods_id = e.currentTarget.dataset['goods_id'];
        wx.navigateTo({
            url: "../goods_detail/goods_detail?goods_id=" + goods_id
        })
    },
    orderRefund: function (e) {
        let order_goods_id = e.currentTarget.dataset['order_goods_id'];
        let order_id = e.currentTarget.dataset['order_id'];
        wx.navigateTo({
            url: "../refund/refund?order_id=" + order_id + '&order_goods_id=' + order_goods_id
        })
    },
    orderReturn: function (e) {
        let order_goods_id = e.currentTarget.dataset['order_goods_id'];
        let order_id = e.currentTarget.dataset['order_id'];
        wx.navigateTo({
            url: "../return/return?order_id=" + order_id + '&order_goods_id=' + order_goods_id
        })
    },
    custormerService: function () {
        wx.navigateTo({
            url: this.data.key ? '../message_detail/message_detail' : '../chooselogin/chooselogin'
        })
    }
})